﻿using CameraSystem;
using GameTimeSystem;
using CharacterSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using EnvironSystem;

public class GameLaunch:MonoBehaviour
{
    public Vector3 lastMousPos;

    public GameObject targetGo;

    public GameObject CameraRootRight;
    public GameObject CameraRootUp;

    public float rotateSpeed = 2;

    public float maxRightStep = 2;
    public float maxUpStep = 2;

    public float attackRadius=5;


    Monster monster;
    private void Awake()
    {
        CameraSystemFacade.Inst.Init();
        CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).FocusTarget = targetGo;
        CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).FadeObjAlpha = 0.5f;
        CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).IsFadeObject = true;
        //CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).CameraRootRight = CameraRootRight;
        //CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).CameraRootUp = CameraRootUp;
        EnvironmentSystemFacade.Inst.Init();
        GameTimeSystemFacade.Inst.Init();

        GameObject go = new GameObject("GameTimeAgent");
        GameTimeCenter agent = go.AddComponent<GameTimeCenter>();
        MonoBehaviour.DontDestroyOnLoad(go);
    }

    private void Update()
    {
        //if (Input.GetKeyDown(KeyCode.U))
        //{
        //    CircleAreaArgs args= new CircleAreaArgs(targetGo.transform.position, attackRadius);
        //    IEnvironmentElement[] elements= EnvironmentSystemFacade.Inst.GetElementsInArea(AreaType.Circle, args);
        //    for (int i = 0; i < elements.Length; i++)
        //    {
        //        ((CharacterBase)elements[i]).name = "Attacked";
        //    }
        //}

        if (Input.GetKeyDown(KeyCode.F1))
        {
            //CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).Shake();
            //CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).ShowCameraEffect(CameraEffectType.RadiaBlur,10,0.5f,0.5f,0.5f);
            monster=(Monster)EnvironmentSystemFacade.Inst.Create(EnvironmentIds.Monster, "Monster");
            monster.targetGo = targetGo ;
        }
        //if (Input.GetMouseButton(0))
        //{
        //    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        //    RaycastHit hitInfo;
        //    Physics.Raycast(ray, out hitInfo);
        //    if (hitInfo.collider!=null)
        //    {
        //        monster.MoveTo(hitInfo.point);
        //    }
            
        //}

        lastMousPos = Input.mousePosition;
    }
}